﻿#ifndef WXPOLYGONEX_H
#define WXPOLYGONEX_H

#include <wx/wx.h>
#include <vector>
#include <algorithm>

class wxPolygonEx
{
public:
    // 构造函数
    wxPolygonEx() = default;
    explicit wxPolygonEx(size_t n, const wxPoint points[]);
    wxPolygonEx(std::initializer_list<wxPoint> points);

    // 添加/删除点
    void append(const wxPoint& point);
    void prepend(const wxPoint& point);
    void insert(size_t index, const wxPoint& point);
    void remove(size_t index);
    void clear();

    // 访问点
    wxPoint& operator[](size_t index);
    const wxPoint& operator[](size_t index) const;
    wxPoint at(size_t index) const;
    wxPoint first() const;
    wxPoint last() const;

    // 容量相关
    size_t size() const;
    bool empty() const;
    bool isClosed() const;

    // 几何操作
    void translate(int dx, int dy);
    wxPolygonEx translated(int dx, int dy) const;
    wxRect boundingRect() const;
    bool containsPoint(const wxPoint& pt) const;

    // 迭代器支持
    std::vector<wxPoint>::iterator begin();
    std::vector<wxPoint>::iterator end();
    std::vector<wxPoint>::const_iterator begin() const;
    std::vector<wxPoint>::const_iterator end() const;

private:
    std::vector<wxPoint> m_points;

    // 点包含检测辅助函数
    bool rayCasting(const wxPoint& pt) const;
};

#endif // WXPOLYGONEX_H
